/*
 *
 * @Author: Jevon
 * @Date: 2021-12-16 10:12:29
 */
export default class VuiClipboardDataItem {
  /**
   *
   * @param {*}
   * @return {*}
   */
  constructor(data) {
    this._item = data || {};
  }

  static FORMATS = {
    text: 'text/plain',
    html: 'text/html',
    png: 'image/png',
    application: 'application/octet-stream'
  };

  set(data, format) {
    this._item[format] = data;
  }

  text(data) {
    this.set(data, VuiClipboardDataItem.FORMATS.text);
  }

  html(data) {
    this.set(data, VuiClipboardDataItem.FORMATS.html);
  }

  png(data) {
    this.set(data, VuiClipboardDataItem.FORMATS.png);
  }

  application(data) {
    this.set(data, VuiClipboardDataItem.FORMATS.application);
  }

  each(func) {
    const item = this.item;
    for (const key in item) {
      func(key, item[key]);
    }
  }

  toClipboardItem() {
    return [new ClipboardItem(this._item)];
  }
}
